using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using GraphAlgsPresentation.Core;
using System.Xml.Serialization;
using System.ComponentModel;

namespace GraphAlgsPresentation.ScriptLibrary
{
    /// <summary>
    /// Provides a change vertex text color
    /// </summary>
    [Serializable]
    public class ChangeVertexTextColor : Command
    {
        private string name;
        private Color newColor;
        private Color oldColor;

        /// <summary>
        /// returns vertex's name
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// returns new vertex's text color
        /// </summary>
        [XmlIgnore]
        public Color NewColor
        {
            get { return newColor; }
            set { newColor = value; }
        }

        /// <summary>
        /// Gets or sets the new color of the XML.
        /// </summary>
        /// <value>The new color of the XML.</value>
        [Browsable(false)]
        public string XMLNewColor
        {
            get { return XmlDataConverter.SerializeColor(this.NewColor); }
            set { this.NewColor = XmlDataConverter.DeserializeColor(value); }
        }

        /// <summary>
        /// Gets or sets the old color.
        /// </summary>
        /// <value>The old color.</value>
        [XmlIgnore]
        [Browsable(false)]
        public Color OldColor
        {
            get { return oldColor; }
            set { oldColor = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeVertexTextColor"/> class.
        /// </summary>
        /// <param name="_name">Vertex's name</param>
        /// <param name="_color">New vertex's text color</param>
        /// <param name="effect">The effect.</param>
        public ChangeVertexTextColor(string _name, Color _color, DrawEffect effect)
        {
            name = _name;
            newColor = _color;
            Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeVertexTextColor"/> class.
        /// </summary>
        /// <param name="id">The vertex's id.</param>
        /// <param name="_color">The color.</param>
        /// <param name="effect">The effect.</param>
        public ChangeVertexTextColor(int id, Color _color, DrawEffect effect)
        {
            name = (id + 1).ToString();
            newColor = _color;
            Effect = effect;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeVertexTextColor"/> class.
        /// </summary>
        public ChangeVertexTextColor()
        {
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        public override void Run()
        {
            LCVertex v = this.Context.GetVertex(name);
            oldColor = v.TextColor;
            v.TextColor = newColor;
            v.Updated = true;
            //this.Context.Layout.ReDraw();
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            LCVertex v = this.Context.GetVertex(name);
            v.TextColor = oldColor;
            v.Updated = true;
            //this.Context.Layout.ReDraw();
        }
    }
}
